package cn.edu.xhu.library_management.iot.controller;

import cn.edu.xhu.library_management.iot.dto.MachineJson;
import cn.edu.xhu.library_management.iot.mqtt.client.MqttSendClient;
import com.alibaba.fastjson2.JSON;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: MMJ
 * @Date: 2023 - 05 - 03
 * @Description: 物联网设备控制下发
 */
@Api(tags = "iot控制设备模块")
@ApiSort(1)
@RestController
@RequestMapping("/lm_iot/command")
public class IotController {
    @Resource(name = "mqttSendClient")
    private MqttSendClient sendClient;

    @GetMapping("/seat/{id}")
    @ApiOperation(value = "下发地址生成二维码",produces="application/json")
    public boolean sendSeatInfo(@PathVariable("id") Integer id){
        String urlPrefix = "http://127.0.0.1:9000/lm_user/user/applet/reservationSeat/seat/" + id;
        MachineJson json = new MachineJson("url", urlPrefix);
        sendClient.publish(false,"/SmartLibrary/sub", JSON.toJSONString(json));
        return true;
    }
}
